package com.rs.service.impl;

import com.alibaba.excel.EasyExcel;
import com.rs.listener.AttendanceListener;
import com.rs.mapper.AttendanceMapper;
import com.rs.pojo.Attendance;
import com.rs.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Service
public class AttendanceServiceImpl implements AttendanceService {
    @Autowired
    private AttendanceMapper attendanceMapper;

    @Override
    public List<Attendance> findAll() {
        return attendanceMapper.findAll();
    }

    @Override
    public void add(Attendance attendance) {
     attendanceMapper.add(attendance);
    }

    @Override
    public void deleteById(String id) {
        attendanceMapper.deleteById(id);
    }

    @Override
    public void updateAttendance(Attendance attendance) {
        attendanceMapper.updateAttendance(attendance);
    }

    @Override
    public void batchDel(Integer[] ids) {
       attendanceMapper.batchDel(ids);
    }

    @Override
    public List<Attendance> findByIds(Integer[] ids) {
        return attendanceMapper.findByIds(ids);
    }

    @Override
    public void upload(MultipartFile file) {
        InputStream inputStream = null;

        //获取输入流
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(inputStream, Attendance.class, new AttendanceListener(attendanceMapper)).sheet().doRead();
    }
}
